var parentID;
var searchInput;
$(function(){
	parentID=$("#parentID").val();
	$('#city-table').datagrid({
				fit:true,
				url:js+'dict/getTreeNodeTabelCity.action?cityID='+parentID,
				idField:'cityID',
				fitColumns: true,
				height: 'auto',
				columns:[[{field:'ck',checkbox:true},
	                {field:'cityName',title:'名称',width:80,sortable:true},
					{field:'cityCode',title:'编号',width:120,sortable:true},
					{field:'cityTypeName',title:'城市类型',width:220,sortable:true},
					{field:'cityTypeLevel',title:'城市等级',width:220,sortable:true}
				]],
				pagination:true,
				rownumbers:true,
				onDblClickRow:function(rowIndex, rowData){
					window.parent.update(rowData);
				}
   });
})
function reloadTable(){
	parentID=$("#parentID").val();
	searchInput = $("#searchInput").val();
	$('#city-table').datagrid({
	 url:js+'dict/getTreeNodeTabelCity.action?cityID='+parentID+"&searchInput="+searchInput,
   });
   $('#city-table').datagrid('reload');
}

function mulDelete(){
	var rows = $('#city-table').datagrid('getSelections');
	if(rows.length==0){
		 $.messager.alert('提示',"请选中要删除的纪录","warming");
		 return;	
	}
	$.messager.confirm("提示！","确定要删除选中地域城市?",function(t){ 
			if(!t) return;
		var cityIDArray = new Array();
		for(var i=0;i<rows.length>0;i++){
			cityIDArray.push(rows[i].cityID);
		}
		var cityIDsStr = cityIDArray.join(",");
		$.post(js+"dict/mulDeleteCity.action",{cityIDsStr:cityIDsStr},function(result){
		     if(result.success){
		     		while(rows&&rows.length>0){
						var index = $('#city-table').datagrid('getRowIndex', rows[0]);
						window.parent.removeTreeNode(rows[0].cityID);
						$('#city-table').datagrid('deleteRow', index);
						rows = $('#city-table').datagrid('getSelections');
					}
					return true;
		      }else{
		          $.messager.alert('提示',"删除不成功","error");	
		          return false;
		      }
		},"json");
	});
}
